#include <iostream>
#include <string>
#include <vector>
#include <cmath>

using namespace std;

bool IsPrime(int a) {
    for (int i = 2; i <= a / 2; i++) {
        if (a % i == 0) {
            return false;
        }
    }
    return true;
}

int main() {
    setlocale(LC_ALL, "Russian");
    string first;
    string second;
    string three;
    cin >> first >> second >> three;
    int f = -1;
    int s = -1;
    int t = -1;
    string nums[] = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" };
    for (int i = 0; i < 10; i++) {
        if (first == nums[i]) {
            f = i;
        }
        if (second == nums[i]) {
            s = i;
        }
        if (three == nums[i]) {
            t = i;
        }
    }
    if (f == -1) {
        cout << "Wrong input" << '\n';
        return 0;
    }
    if (s == -1) {
        cout << "Wrong input" << '\n';
        return 0;
    }
    if (t == -1) {
        cout << "Wrong input" << '\n';
        return 0;
    }
    int res_num = f * 100 + s * 10 + t;
    int number_minus = res_num;
    int number_plus = res_num;
    while (true) {
        if (IsPrime(number_plus)) {
            break;
        }
        number_plus++;
    }
    while (true) {
        if (IsPrime(number_minus)) {
            break;
        }
        number_minus--;
    }
    if ((abs(number_minus - res_num)) < (abs(number_plus - res_num))) {
        cout << number_minus << '\n';
    }
    else if ((abs(number_minus - res_num)) > (abs(number_plus - res_num))) {
        cout << number_plus << '\n';
    }
    else {
        cout << number_plus << '\n';
    }
}
